www.gusucode.com > VC++ 汽配销售管理系统(Access)源码程序 > VC++ 汽配销售管理系统(Access)源码程序/源码/DStore.cpp

    //Download by http://www.NewXing.com
// DStore.cpp : implementation file
//

#include "stdafx.h"
#include "qpglxt.h"
#include "DStore.h"
#include "DBaseQuery.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDStore dialog


CDStore::CDStore(CWnd* pParent /*=NULL*/)
	: CDialog(CDStore::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDStore)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDStore::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDStore)
	DDX_Control(pDX, IDC_SPXX_BUTUNDO, m_ButUndo);
	DDX_Control(pDX, IDC_SPXX_BUTSAVE, m_ButSave);
	DDX_Control(pDX, IDC_SPXX_BUTEXIT, m_ButExit);
	DDX_Control(pDX, IDC_SPXX_BUTDELE, m_ButDele);
	DDX_Control(pDX, IDC_SPXX_BUTCHANGE, m_ButChange);
	DDX_Control(pDX, IDC_SPXX_BUTADD, m_ButAdd);
	DDX_Control(pDX, IDC_EDTTEL, m_EdtTel);
	DDX_Control(pDX, IDC_EDTMEM, m_EdtMem);
	DDX_Control(pDX, IDC_EDT_ADDR, m_EdtAddr);
	DDX_Control(pDX, IDC_CK_EDTNAME, m_EdtName);
	DDX_Control(pDX, IDC_CK_EDTID, m_EdtID);
	DDX_Control(pDX, IDC_CK_COMADMIN, m_ComAdmin);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDStore, CDialog)
	//{{AFX_MSG_MAP(CDStore)
	ON_BN_CLICKED(IDC_SPXX_BUTADD, OnSpxxButadd)
	ON_BN_CLICKED(IDC_SPXX_BUTCHANGE, OnSpxxButchange)
	ON_BN_CLICKED(IDC_SPXX_BUTDELE, OnSpxxButdele)
	ON_BN_CLICKED(IDC_SPXX_BUTSAVE, OnSpxxButsave)
	ON_BN_CLICKED(IDC_SPXX_BUTUNDO, OnSpxxButundo)
	ON_BN_CLICKED(IDC_SPXX_BUTEXIT, OnSpxxButexit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDStore message handlers

void CDStore::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

void CDStore::Clear()
{
	m_EdtTel.SetWindowText("");
	m_EdtMem.SetWindowText("");
	m_EdtAddr.SetWindowText("");
	m_EdtName.SetWindowText("");
	m_EdtID.SetWindowText("");
	m_ComAdmin.SetWindowText("");
}

void CDStore::Display(CString ID)
{
	RxRecordset Drxt;
	CString sSQL;
	if(ID.IsEmpty())
		return;

	sSQL.Format("SELECT * FROM 仓库信息查询 WHERE 编号 =%s",ID);
	Drxt.Open(sSQL,adCmdText);

	CString sID,sName,sAddr,sTel,sAdmin,sMem;
	sID=Drxt.GetFieldValue("编号");
	sName=Drxt.GetFieldValue("名称");
	sAddr=Drxt.GetFieldValue("地址");
	sTel=Drxt.GetFieldValue("电话");
	sAdmin=Drxt.GetFieldValue("管理员");
	sMem=Drxt.GetFieldValue("备注");

	m_EdtTel.SetWindowText(sTel);
	m_EdtMem.SetWindowText(sMem);
	m_EdtAddr.SetWindowText(sAddr);
	m_EdtName.SetWindowText(sName);
	m_EdtID.SetWindowText(sID);
	m_ComAdmin.SetWindowText(sAdmin);
}

void CDStore::Enabled(bool bEnabled)
{
	m_EdtTel.EnableWindow(bEnabled);
	m_EdtMem.EnableWindow(bEnabled);
	m_EdtAddr.EnableWindow(bEnabled);
	m_EdtName.EnableWindow(bEnabled);
	m_ComAdmin.EnableWindow(bEnabled);
	m_ButUndo.EnableWindow(bEnabled);
	m_ButSave.EnableWindow(bEnabled);
	m_ButExit.EnableWindow(!bEnabled);
	m_ButDele.EnableWindow(!bEnabled);
	m_ButChange.EnableWindow(!bEnabled);
	m_ButAdd.EnableWindow(!bEnabled);

}

BOOL CDStore::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CDBaseQuery* Parent =(CDBaseQuery*)this->FindWindow(NULL,"仓库信息查询");
	CString sSQL,sID;
	sID=Parent->m_Grid.GetItemText(Parent->m_CurrentRow,0);
	m_sID=sID;
	this->Display(sID);
	rst.Open("员工信息表");
	this->m_ComAdmin.SetRecordset(rst,"姓名");
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CDStore::OnSpxxButadd() 
{
	AddOrChange=1;
	CString sNewID;
	sNewID=ado.AutoNumber("仓库信息表","编号","",1);
	this->Clear();
	m_EdtID.SetWindowText(sNewID);
	this->Enabled(true);
	this->m_EdtName.SetFocus();		
}

void CDStore::OnSpxxButchange() 
{
	AddOrChange=2;
	this->Enabled(true);
	this->m_EdtName.SetFocus();		
	
}

void CDStore::OnSpxxButdele() 
{
	if(MessageBox("确定要删除记录吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	CString cID,sSQL;
	this->m_EdtID.GetWindowText(cID);
	sSQL.Format("DELETE FROM 仓库信息表 WHERE 编号=%s",cID);
	rst.Open(sSQL,adCmdText);
	this->OnCancel();	
	
}

void CDStore::OnSpxxButsave() 
{
	if(MessageBox("确定要保存记录吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	CString sSQL,sID,sName,sAddr,sTel,sAdmin,sMem,sAdminID;
	m_EdtTel.GetWindowText(sTel);
	m_EdtMem.GetWindowText(sMem);
	m_EdtAddr.GetWindowText(sAddr);
	m_EdtName.GetWindowText(sName);
	m_EdtID.GetWindowText(sID);
	m_ComAdmin.GetWindowText(sAdmin);
	sAdminID=ado.FieldToOtherField("员工信息表","姓名",sAdmin,"编号",1);
	if(this->AddOrChange==1)//添加
		sSQL.Format("INSERT INTO 仓库信息表 VALUES(%s,'%s','%s','%s',%s,'%s')",sID,sName,sAddr,sTel,sAdminID,sMem);
	else//修改
		sSQL.Format("UPDATE 仓库信息表 SET 名称='%s',地址='%s',电话='%s',管理员=%s,备注='%s' WHERE 编号=%s",sName,sAddr,sTel,sAdminID,sMem,sID);
	rst.Open(sSQL,adCmdText);
	this->Enabled(false);
	this->AddOrChange=0;		
}

void CDStore::OnSpxxButundo() 
{
	if(MessageBox("确定要撤消操作吗?"," 系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	this->Enabled(false);
	this->Clear();
	this->Display(m_sID);
	
}

void CDStore::OnSpxxButexit() 
{
	this->OnCancel();	
}